export const animation = (
  from: number,
  to: number,
  duration: number,
  callback: (progress: number) => void
) => {
  const speed = (to - from) / duration
  const start = Date.now()
  const _run = () => {
    let id: number = 0

    const now = Date.now()
    const progress = from + (now - start) * speed
    if (progress > to) {
      callback(Math.floor(progress))
      return cancelAnimationFrame(id)
    }
    id = requestAnimationFrame(_run)
    callback(Math.floor(progress))
  }
  requestAnimationFrame(_run)
}
